package ca.benow.transmission.model;

import java.text.DecimalFormat;

import org.json.JSONObject;

public class TorrentFile {

	String name;
	long size;
	long completed;

	public TorrentFile(JSONObject object) {
		name = object.optString("name");
		completed = (object.optLong("bytesCompleted"));
		size = (object.optLong("length"));

	}

	public String getName() {
		return name;
	}

	public long getSize() {
		return size;
	}

	public long getCompleted() {
		return completed;
	}

	public static String prettifysize(long size) {
		Double mod = ((Long) size).doubleValue();

		int modulo;
		for (modulo = 0; modulo < 3; modulo++) {
			if ((mod / 1024) >= 1) {
				mod = mod / 1024;
			} else {
				break;
			}
		}
		DecimalFormat df = new DecimalFormat("#.##");
		String value = df.format(mod);
		// System.out.println("Size: "+String.valueOf(size)+" | Modulo: "+String.valueOf(modulo));
		String unity = "";
		switch (modulo) {
		case 0:
			unity = value.concat(" o");
			break;
		case 1:// ko
			unity = value.concat(" Ko");
			break;
		case 2:// Mo
			unity = value.concat(" Mo");
			break;
		case 3:// Go
			unity = value.concat(" Go");
			break;
		default:
			unity = "> ".concat(value).concat(" Go");
		}
		return unity;
	}
}
